import 'package:flutter/material.dart';
import 'package:flutter_ahj_app/app/yhpc/YhpcViewModel.dart';
import 'package:flutter_ahj_app/base/basewidget/view/BaseWidget.dart';
import 'package:flutter_ahj_app/base/utils/JUIKit/JText.dart';
import 'package:flutter_ahj_app/base/utils/mTopBar.dart';
import 'package:flutter_ahj_app/base/values/SQColor.dart';
import 'package:flutter_ahj_app/base/widget/NoneData.dart';

class PcnrView extends BaseStatefulWidget {
  var pcnrList;
  PcnrView(this.pcnrList);
  @override
  State<StatefulWidget> initState() {
    // TODO: implement initState
    // throw UnimplementedError();
    return PcnrViewState();
  }
}

class PcnrViewState extends BaseState<YhpcViewModel, PcnrView> {
  Map _data = {};
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _data = widget.pcnrList;
  }

  @override
  Widget initWidget() {
    return Scaffold(
      backgroundColor: Color(0xfff4f5f6),
      appBar: MTopBar(elevation: 0, title: '选择排查内容', rightButtonText: '确定', onRightButtonClick: () {
        Navigator.pop(context, _data);
      })
          .create(),
      body: _data == null ? NoneData() : _bodyView(),
    );
  }

  _bodyView() {
    return Container(
      margin: EdgeInsets.all(15),
      child: SingleChildScrollView(
        child: ListView.builder(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemCount: 1,
            itemBuilder: (context, index) {
              return InkWell(
                onTap: () {
                  setState(() {
                    _data['isSel'] = _data['isSel'] == null
                        ? true
                        : !_data['isSel'];
                  });
                },
                child: Column(
                  children: [
                    Container(
                      decoration: BoxDecoration(
                        color: SQColor.white,
                        borderRadius: BorderRadius.circular(8),
                      ),
                      padding: EdgeInsets.only(left: 15),
                      child: Row(
                        children: [
                          Expanded(
                            child: Container(
                              margin: EdgeInsets.only(top: 10, bottom: 10),
                              child: JText(_data['name']),
                            ),
                          ),
                          Checkbox(
                            value: _data['isSel'] == null
                                ? false
                                : _data['isSel'],
                            onChanged: (value) {
                              setState(() {
                                _data['isSel'] =
                                    _data['isSel'] == null
                                        ? true
                                        : !_data['isSel'];
                              });
                            },
                          ),
                        ],
                      ),
                    ),
                    Container(
                      height: 10,
                      color: Color(0xfff6f6f6),
                      width: double.infinity,
                    ),
                  ],
                ),
              );
            }),
      ),
    );
  }
}
